/// Text Overlay Application: Monitor Class
/// This class contains functions to monitor the computer's memory usage and
/// performance.


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime.InteropServices;
using CommLayer;
using Tamir.IPLib;
using Tamir.IPLib.Packets;
using Magnolia;

namespace TextOverlay
{
    struct CMonitor
    {
        /// <summary>
        /// Retrieves the amount of available Ram memory in the system
        /// </summary>
        /// <returns>the amount of available Ram memory in the system in MB</returns>
        public float GetRamUsage()
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes"); 
            return ramCounter.NextValue();
        }
        
        /// <summary>
        /// Retrieves the amount of PageFile memory being used by the system
        /// </summary>
        /// <returns>the amount of PageFile memory being used by the system in MB</returns>
        public int GetPfUsage()
        {
            long TotalMemory = 0;
            Process[] PL = Process.GetProcesses();
            foreach (Process P in PL)
            {
                TotalMemory += P.PeakPagedMemorySize64;
            }

            return Convert.ToInt32((TotalMemory / 1024) / 1024);
        }

    }
}